<?php

namespace App\Http\Models;

use App\Support\Data;
use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;


class Medical extends BaseModel
{
    use SoftDeletes;
    use HasDateTimeFormatter;
    protected $table = 'medical';
    public $timestamps = true;

    public $default_image = 'https://resources.gongshicloud.com/default/20220615174538-62a9aa425e8ad.png';


    protected $fillable = [
        'id',
        'act_id',
        'name',
        'sex',
        'age',
        // hp检查时间
        'hp_check_date',
        // hp检查方法单选
        'hp_check_method',
        // hp检查方法录入
        'hp_check_method_input',
        // hp检查结果
        'hp_check_result',

        // 疾病诊断
        'disease_diagnosis',
        // 疾病诊断输入
        'disease_diagnosis_input',

        // 胃镜诊断单选
        'gastroscopy_diagnosis',
        // 胃镜诊断输入
        'gastroscopy_diagnosis_input',

        // 病理诊断单选
        'case_diagnosis',
        // 病理诊断输入
        'case_diagnosis_input',

        // 既往hp感染治疗史单选
        'hp_treatment_history',
        // 既往hp感染治疗史输入
        'hp_treatment_history_input',

        // 用药记录复选框
        'medical_record_checkbox',

        // ppi输入记录
        'ppi_input',
        // ppi用法用量
        'ppi_usage_dosage',

        // 铋剂输入
        'bismuth_input',
        // 铋剂用法用量
        'bismuth_usage_dosage',

        // 抗生素1输入
        'antibiotic1_input',
        // 抗生素1用法用量
        'antibiotic1_usage_dosage',
        // 抗生素2输入
        'antibiotic2_input',
        // 抗生素2用法用量
        'antibiotic2_usage_dosage',

        // 荜铃胃痛颗粒输入
        'biling_granules_input',
        // 荜铃胃痛颗粒用法用量
        'biling_granules_usage_dosage',

        // 开始服药时间
        'start_taking_medicine',
        // 停止服药时间
        'stop_taking_medicine',

        // 是否调整用药方案
        'adjust_medication',
        // 调整药物原因
        'adjust_medication_reason',

        // 治疗前-程度-上腹痛
        'pre_degree_ep_pain',
        // 治疗前-程度-餐后饱张
        'pre_degree_after_meal_satiety',
        //  治疗前-程度-早饱
        'pre_degree_premature_satiety',
        // 治疗前-程度-上腹烧灼
        'pre_degree_burn_upper_abdomen',
        'pre_degree_amount',
        // 治疗前-频率-上腹痛
        'pre_frequency_ep_pain',
        //治疗前-频率-餐后饱张
        'pre_frequency_after_meal_satiety',
        //治疗前-频率-早饱
        'pre_frequency_premature_satiety',
        //治疗前-频率-上腹烧灼
        'pre_frequency_burn_upper_abdomen',
        'pre_frequency_amount',
        //其他-泛酸
        'pre_other_acid_regurgitation',
        //其他-烧心
        'pre_other_heartburn',
        //其他-大便
        'pre_other_shit',
        //其他-疲乏
        'pre_other_fatigued',
        //其他-睡眠差
        'pre_other_poor_sleep',
        //其他-烦躁易怒
        'pre_other_irritability',
        //其他-焦虑
        'pre_other_anxiety',
        // 其他-抑郁
        'pre_other_depressed',
        //治疗后检查时间
        'after_hp_check_date',
        //  治疗后检查方法
        'after_hp_check_method',
        // 治疗后检查方法输入
        'after_hp_check_method_input',
        //  治疗后检查结果
        'after_hp_check_result',
        //  治疗后-程度-上腹痛
        'after_post_degree_ep_pain',
        // 治疗后-程度-餐后饱张
        'after_post_degree_after_meal_satiety',
        //  治疗后-程度-早饱
        'after_post_degree_premature_satiety',
        // 治疗后-程度-上腹烧灼
        'after_post_degree_burn_upper_abdomen',
        'after_post_degree_amount',
        //治疗后-频率-上腹痛
        'after_post_frequency_ep_pain',
        // 治疗后-频率-餐后饱胀
        'after_post_frequency_after_meal_satiety',
        //  治疗后-频率-早饱
        'after_post_frequency_premature_satiety',
        // 治疗后-频率-上腹烧灼
        'after_post_frequency_burn_upper_abdomen',
        'after_post_frequency_amount',
        // 治疗后-其他-泛酸
        'after_other_acid_regurgitation',
        //  治疗后-其他-烧心
        'after_other_heartburn',
        //  治疗后-其他-大便
        'after_other_shit',
        // 治疗后-其他-疲乏
        'after_other_fatigued',
        //  治疗后-其他-睡眠差
        'after_other_poor_sleep',
        //  治疗后-其他-烦躁易怒
        'after_other_irritability',
        //  治疗后-其他-焦虑
        'after_other_anxiety',
        //  治疗后-其他-抑郁
        'after_other_depressed',

        // 是否产生不良反应 1是 2否
        'adversereaction',
        // 反应表现复选id
        'adversereaction_group',
        // 反应表现其他输入
        'adversereaction_group_input',
        // 日期
        'adversereaction_date',
        // 是否用药后立即发生 1是 2否
        'adversereaction_immediately',
        // 用药几小时
        'adversereaction_time_input',
        // 不良反应的严重程度单选id
        'adversereaction_degree',
        // 药物相关 单选id
        'adversereaction_related',
        // 邀请码
        'invitation_code',
        // 病例附件
        'attachments',

        'user_id',
        'status',
    ];

    protected $hidden = [
        // 'status',
        'deleted_at'
        // 'examine_time'

    ];

    protected $casts = [
        'created_at' => 'datetime:Y-m-d',
        'updated_at' => 'datetime:Y-m-d',
        // 'hp_check_date' => 'datetime:Y-m-d',
        // 'start_taking_medicine' => 'datetime:Y-m-d',
        // 'stop_taking_medicine' => 'datetime:Y-m-d',
        // 'after_hp_check_date' => 'datetime:Y-m-d',
        // 'adversereaction_date' => 'datetime:Y-m-d',
        // 'invoice_img' => array,
        // 'discharge_summary_img' => array,
    ];


    public function getAttachmentsDataAttribute($value)
    {
        if (empty($value)) {
            return [];
        }

        $arr = [];
        $url_arr = explode(',', $value);

        foreach ($url_arr as $key => $val) {

            if (!empty($val)) {
                $url = parse_url($val);
                $fileName = basename($url['path']);
                $w_param = pathinfo($val);
                $data['name'] = $fileName;
                $data['url'] = $val;
                $data['ext'] = empty($w_param['extension']) ? '' : $w_param['extension'];
                array_push($arr, $data);
            }
        }
        return $arr;
    }

    public function getSexTextAttribute($value)
    {
        $sex = Data::getSex();
        return isset($sex[$value]) && !empty($sex[$value]) ? $sex[$value] : '';
    }

    public function getMedicalRecordCheckboxAttribute($value)
    {
        if (isset($value) && !empty($value)) {
            return explode(',', $value);
        } else {
            return [];
        }
    }


    // adversereaction_group
    public function getAdversereactionGroupAttribute($value)
    {
        if (isset($value) && !empty($value)) {
            return explode(',', $value);
        } else {
            return [];
        }
    }



    // hp检查时间
    public function getHpCheckDateAttribute($value)
    {
        if (isInvalidDateTime($value)) {
            return '';
        } else {
            return date('Y-m-d', strtotime($value));
        }
    }
    //start_taking_medicine
    public function getStartTakingMedicineAttribute($value)
    {
        if (isInvalidDateTime($value)) {
            return '';
        } else {
            return date('Y-m-d', strtotime($value));
        }
    }

    // stop_taking_medicine
    public function getStopTakingMedicineAttribute($value)
    {
        if (isInvalidDateTime($value)) {
            return '';
        } else {
            return date('Y-m-d', strtotime($value));
        }
    }

    // after_hp_check_date
    public function getAfterHpCheckDateAttribute($value)
    {
        if (isInvalidDateTime($value)) {
            return '';
        } else {
            return date('Y-m-d', strtotime($value));
        }
    }

    // adversereaction_date
    public function getAdversereactionDateAttribute($value)
    {
        if (isInvalidDateTime($value)) {
            return '';
        } else {
            return date('Y-m-d', strtotime($value));
        }
    }



    /**
     * 我的病例
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2022-03-07
     * @param [int] $page
     * @param [int] $limit
     * @param [array] $where
     * @param [array] $field
     * @return mixed
     */
    public function getMedicalList($page, $limit, $where = [], $field = ['*'])
    {

        $where = function ($query) use ($where) {

            $query->where('status', 1);

            if (isset($where['name']) && $where['name'] != '') {
                $query->where('title', 'like', '%' . $where['name'] . '%');
            }

            if (isset($where['user_id']) && $where['user_id'] != '') {
                $query->where('user_id', $where['user_id']);
            }
        };
        return $this->paginate($page, $limit, $where, $field, 'desc', 'page', '');
    }


    /**
     * 我的病例
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2022-03-07
     * @param [int] $page
     * @param [int] $limit
     * @param [array] $where
     * @param [array] $field
     * @return mixed
     */
    public function getMedicalListByUser($page, $limit, $where = [], $field = ['*'])
    {

        $where = function ($query) use ($where) {

            // $query->where('status', 1);

            if (isset($where['status']) && $where['status'] != '') {
                $query->where('status', $where['status']);
            }

            if (isset($where['user_id']) && $where['user_id'] != '') {
                $query->where('user_id', $where['user_id']);
            }
        };
        return $this->paginate($page, $limit, $where, $field, 'desc', 'page',  '');
    }

    /**
     * 我的病例
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2024-02-02
     * @param [array] $where
     * @param [array] $field
     * @return mixed
     */
    public function getListByUser($where = [], $field = ['*'])
    {

        $where = function ($query) use ($where) {

            if (isset($where['user_id']) && $where['user_id'] != '') {
                $query->where('user_id', $where['user_id']);
            }
        };
        return $this->where($where)->select($field)->get();
    }


    /**
     * 病例库修改
     *
     * @Author hechengwei
     * @email chichiooo@sina.com
     * @DateTime 2022-05-11
     * @param array $payload
     * @param int $id
     * @return void
     */
    public static function updateMedical($payload, $id)
    {
        Log::info('病例提交数据：' . json_encode($payload));
        $model = self::find($id);
        $model->name = isset($payload['name']) && !empty($payload['name']) ? $payload['name'] : '';
        $model->sex = isset($payload['sex']) && !empty($payload['sex']) ? $payload['sex'] : '';
        $model->age = isset($payload['age']) && !empty($payload['age']) ? $payload['age'] : '';

        // hp检查时间
        // 'hp_check_date',
        $model->hp_check_date = isset($payload['hp_check_date']) && !empty($payload['hp_check_date']) ? $payload['hp_check_date'] : '';
        // hp检查方法单选
        // 'hp_check_method',
        $model->hp_check_method = isset($payload['hp_check_method']) && !empty($payload['hp_check_method']) ? $payload['hp_check_method'] : '';
        // hp检查方法录入
        // 'hp_check_method_input',
        $model->hp_check_method_input = isset($payload['hp_check_method_input']) && !empty($payload['hp_check_method_input']) ? $payload['hp_check_method_input'] : '';
        // hp检查结果
        // 'hp_check_result',
        $model->hp_check_result = isset($payload['hp_check_result']) && !empty($payload['hp_check_result']) ? $payload['hp_check_result'] : '';
        // 疾病诊断
        // 'disease_diagnosis',
        $model->disease_diagnosis = isset($payload['disease_diagnosis']) && !empty($payload['disease_diagnosis']) ? $payload['disease_diagnosis'] : '';
        // 疾病诊断输入
        // 'disease_diagnosis_input',
        $model->disease_diagnosis_input = isset($payload['disease_diagnosis_input']) && !empty($payload['disease_diagnosis_input']) ? $payload['disease_diagnosis_input'] : '';
        // 胃镜诊断单选
        // 'gastroscopy_diagnosis',
        $model->gastroscopy_diagnosis = isset($payload['gastroscopy_diagnosis']) && !empty($payload['gastroscopy_diagnosis']) ? $payload['gastroscopy_diagnosis'] : '';
        // 胃镜诊断输入
        // 'gastroscopy_diagnosis_input',
        $model->gastroscopy_diagnosis_input = isset($payload['gastroscopy_diagnosis_input']) && !empty($payload['gastroscopy_diagnosis_input']) ? $payload['gastroscopy_diagnosis_input'] : '';
        // 病理诊断单选
        // 'case_diagnosis',
        $model->case_diagnosis = isset($payload['case_diagnosis']) && !empty($payload['case_diagnosis']) ? $payload['case_diagnosis'] : '';
        // 病理诊断输入
        // 'case_diagnosis_input',
        $model->case_diagnosis_input = isset($payload['case_diagnosis_input']) && !empty($payload['case_diagnosis_input']) ? $payload['case_diagnosis_input'] : '';
        // 既往hp感染治疗史单选
        // 'hp_treatment_history',
        $model->hp_treatment_history = isset($payload['hp_treatment_history']) && !empty($payload['hp_treatment_history']) ? $payload['hp_treatment_history'] : '';
        // 既往hp感染治疗史输入
        // 'hp_treatment_history_input',
        $model->hp_treatment_history_input = isset($payload['hp_treatment_history_input']) && !empty($payload['hp_treatment_history_input']) ? $payload['hp_treatment_history_input'] : '';
        // 用药记录复选框
        // 'medical_record_checkbox',
        $model->medical_record_checkbox = isset($payload['medical_record_checkbox']) && !empty($payload['medical_record_checkbox']) ? $payload['medical_record_checkbox'] : '';
        // ppi输入记录
        // 'ppi_input',
        $model->ppi_input = isset($payload['ppi_input']) && !empty($payload['ppi_input']) ? $payload['ppi_input'] : '';
        // ppi用法用量
        // 'ppi_usage_dosage',
        $model->ppi_usage_dosage = isset($payload['ppi_usage_dosage']) && !empty($payload['ppi_usage_dosage']) ? $payload['ppi_usage_dosage'] : '';
        // 铋剂输入
        // 'bismuth_input',
        $model->bismuth_input = isset($payload['bismuth_input']) && !empty($payload['bismuth_input']) ? $payload['bismuth_input'] : '';
        // 铋剂用法用量
        // 'bismuth_usage_dosage',
        $model->bismuth_usage_dosage = isset($payload['bismuth_usage_dosage']) && !empty($payload['bismuth_usage_dosage']) ? $payload['bismuth_usage_dosage'] : '';
        // 抗生素1输入
        // 'antibiotic1_input',
        $model->antibiotic1_input = isset($payload['antibiotic1_input']) && !empty($payload['antibiotic1_input']) ? $payload['antibiotic1_input'] : '';
        // 抗生素1用法用量
        // 'antibiotic1_usage_dosage',
        $model->antibiotic1_usage_dosage = isset($payload['antibiotic1_usage_dosage']) && !empty($payload['antibiotic1_usage_dosage']) ? $payload['antibiotic1_usage_dosage'] : '';
        // 抗生素2输入
        // 'antibiotic2_input',
        $model->antibiotic2_input = isset($payload['antibiotic2_input']) && !empty($payload['antibiotic2_input']) ? $payload['antibiotic2_input'] : '';
        // 抗生素2用法用量
        // 'antibiotic2_usage_dosage',
        $model->antibiotic2_usage_dosage = isset($payload['antibiotic2_usage_dosage']) && !empty($payload['antibiotic2_usage_dosage']) ? $payload['antibiotic2_usage_dosage'] : '';
        // 荜铃胃痛颗粒输入
        // 'biling_granules_input',
        $model->biling_granules_input = isset($payload['biling_granules_input']) && !empty($payload['biling_granules_input']) ? $payload['biling_granules_input'] : '';
        // 荜铃胃痛颗粒用法用量
        // 'biling_granules_usage_dosage',
        $model->biling_granules_usage_dosage = isset($payload['biling_granules_usage_dosage']) && !empty($payload['biling_granules_usage_dosage']) ? $payload['biling_granules_usage_dosage'] : '';
        // 开始服药时间
        // 'start_taking_medicine',
        $model->start_taking_medicine = isset($payload['start_taking_medicine']) && !empty($payload['start_taking_medicine']) ? $payload['start_taking_medicine'] : '';
        // 停止服药时间
        // 'stop_taking_medicine',
        $model->stop_taking_medicine = isset($payload['stop_taking_medicine']) && !empty($payload['stop_taking_medicine']) ? $payload['stop_taking_medicine'] : '';
        // 是否调整用药方案
        // 'adjust_medication',
        $model->adjust_medication = isset($payload['adjust_medication']) && !empty($payload['adjust_medication']) ? $payload['adjust_medication'] : '';
        // 调整药物原因
        // 'adjust_medication_reason',
        $model->adjust_medication_reason = isset($payload['adjust_medication_reason']) && !empty($payload['adjust_medication_reason']) ? $payload['adjust_medication_reason'] : '';
        // 治疗前-程度-上腹痛
        // 'pre_degree_ep_pain',
        $model->pre_degree_ep_pain = isset($payload['pre_degree_ep_pain']) && !empty($payload['pre_degree_ep_pain']) ? $payload['pre_degree_ep_pain'] : '';
        // 治疗前-程度-餐后饱张
        // 'pre_degree_after_meal_satiety',
        $model->pre_degree_after_meal_satiety = isset($payload['pre_degree_after_meal_satiety']) && !empty($payload['pre_degree_after_meal_satiety']) ? $payload['pre_degree_after_meal_satiety'] : '';
        //  治疗前-程度-早饱
        // 'pre_degree_premature_satiety',
        $model->pre_degree_premature_satiety = isset($payload['pre_degree_premature_satiety']) && !empty($payload['pre_degree_premature_satiety']) ? $payload['pre_degree_premature_satiety'] : '';
        // 治疗前-程度-上腹烧灼
        // 'pre_degree_burn_upper_abdomen',
        $model->pre_degree_burn_upper_abdomen = isset($payload['pre_degree_burn_upper_abdomen']) && !empty($payload['pre_degree_burn_upper_abdomen']) ? $payload['pre_degree_burn_upper_abdomen'] : '';
        // 治疗前-程度-总分
        $model->pre_degree_amount = isset($payload['pre_degree_amount']) && !empty($payload['pre_degree_amount']) ? $payload['pre_degree_amount'] : '';
        // 治疗前-频率-上腹痛
        // 'pre_frequency_ep_pain',
        $model->pre_frequency_ep_pain = isset($payload['pre_frequency_ep_pain']) && !empty($payload['pre_frequency_ep_pain']) ? $payload['pre_frequency_ep_pain'] : '';
        //治疗前-频率-餐后饱张
        // 'pre_frequency_after_meal_satiety',
        $model->pre_frequency_after_meal_satiety = isset($payload['pre_frequency_after_meal_satiety']) && !empty($payload['pre_frequency_after_meal_satiety']) ? $payload['pre_frequency_after_meal_satiety'] : '';
        //治疗前-频率-早饱
        // 'pre_frequency_premature_satiety',
        $model->pre_frequency_premature_satiety = isset($payload['pre_frequency_premature_satiety']) && !empty($payload['pre_frequency_premature_satiety']) ? $payload['pre_frequency_premature_satiety'] : '';
        //治疗前-频率-上腹烧灼
        // pre_frequency_burn_upper_abdomen
        $model->pre_frequency_burn_upper_abdomen = isset($payload['pre_frequency_burn_upper_abdomen']) && !empty($payload['pre_frequency_burn_upper_abdomen']) ? $payload['pre_frequency_burn_upper_abdomen'] : '';
        // 治疗前-频率-总分
        // 'pre_frequency_amount',
        $model->pre_frequency_amount = isset($payload['pre_frequency_amount']) && !empty($payload['pre_frequency_amount']) ? $payload['pre_frequency_amount'] : '';


        //其他-泛酸
        // 'pre_other_acid_regurgitation',
        $model->pre_other_acid_regurgitation = isset($payload['pre_other_acid_regurgitation']) && !empty($payload['pre_other_acid_regurgitation']) ? $payload['pre_other_acid_regurgitation'] : '';
        //其他-烧心
        // 'pre_other_heartburn',
        $model->pre_other_heartburn = isset($payload['pre_other_heartburn']) && !empty($payload['pre_other_heartburn']) ? $payload['pre_other_heartburn'] : '';
        //其他-大便
        // 'pre_other_shit',
        $model->pre_other_shit = isset($payload['pre_other_shit']) && !empty($payload['pre_other_shit']) ? $payload['pre_other_shit'] : '';
        //其他-疲乏
        // 'pre_other_fatigued',
        $model->pre_other_fatigued = isset($payload['pre_other_fatigued']) && !empty($payload['pre_other_fatigued']) ? $payload['pre_other_fatigued'] : '';
        //其他-睡眠差
        // 'pre_other_poor_sleep',
        $model->pre_other_poor_sleep = isset($payload['pre_other_poor_sleep']) && !empty($payload['pre_other_poor_sleep']) ? $payload['pre_other_poor_sleep'] : '';
        //其他-烦躁易怒
        // 'pre_other_irritability',
        $model->pre_other_irritability = isset($payload['pre_other_irritability']) && !empty($payload['pre_other_irritability']) ? $payload['pre_other_irritability'] : '';
        //其他-焦虑
        // 'pre_other_anxiety',
        $model->pre_other_anxiety = isset($payload['pre_other_anxiety']) && !empty($payload['pre_other_anxiety']) ? $payload['pre_other_anxiety'] : '';
        // 其他-抑郁
        // 'pre_other_depressed',
        $model->pre_other_depressed = isset($payload['pre_other_depressed']) && !empty($payload['pre_other_depressed']) ? $payload['pre_other_depressed'] : '';
        //治疗后检查时间
        // 'after_hp_check_date',
        $model->after_hp_check_date = isset($payload['after_hp_check_date']) && !empty($payload['after_hp_check_date']) ? $payload['after_hp_check_date'] : '';
        //  治疗后检查方法
        // 'after_hp_check_method',
        $model->after_hp_check_method = isset($payload['after_hp_check_method']) && !empty($payload['after_hp_check_method']) ? $payload['after_hp_check_method'] : '';
        // 治疗后检查方法输入
        // 'after_hp_check_method_input',
        $model->after_hp_check_method_input = isset($payload['after_hp_check_method_input']) && !empty($payload['after_hp_check_method_input']) ? $payload['after_hp_check_method_input'] : '';
        //  治疗后检查结果
        // 'after_hp_check_result',
        $model->after_hp_check_result = isset($payload['after_hp_check_result']) && !empty($payload['after_hp_check_result']) ? $payload['after_hp_check_result'] : '';
        //  治疗后-程度-上腹痛
        // 'after_post_degree_ep_pain',
        $model->after_post_degree_ep_pain = isset($payload['after_post_degree_ep_pain']) && !empty($payload['after_post_degree_ep_pain']) ? $payload['after_post_degree_ep_pain'] : '';
        // 治疗后-程度-餐后饱张
        // 'after_post_degree_after_meal_satiety',
        $model->after_post_degree_after_meal_satiety = isset($payload['after_post_degree_after_meal_satiety']) && !empty($payload['after_post_degree_after_meal_satiety']) ? $payload['after_post_degree_after_meal_satiety'] : '';
        //  治疗后-程度-早饱
        // 'after_post_degree_premature_satiety',
        $model->after_post_degree_premature_satiety = isset($payload['after_post_degree_premature_satiety']) && !empty($payload['after_post_degree_premature_satiety']) ? $payload['after_post_degree_premature_satiety'] : '';
        // 治疗后-程度-上腹烧灼
        // 'after_post_degree_burn_upper_abdomen',
        $model->after_post_degree_burn_upper_abdomen = isset($payload['after_post_degree_burn_upper_abdomen']) && !empty($payload['after_post_degree_burn_upper_abdomen']) ? $payload['after_post_degree_burn_upper_abdomen'] : '';

        // 治疗后-症状-总分
        // 'after_post_degree_amount',
        $model->after_post_degree_amount = isset($payload['after_post_degree_amount']) && !empty($payload['after_post_degree_amount']) ? $payload['after_post_degree_amount'] : '';

        //治疗后-频率-上腹痛
        // 'after_post_frequency_ep_pain',
        $model->after_post_frequency_ep_pain = isset($payload['after_post_frequency_ep_pain']) && !empty($payload['after_post_frequency_ep_pain']) ? $payload['after_post_frequency_ep_pain'] : '';
        // 治疗后-频率-餐后饱胀
        // 'after_post_frequency_after_meal_satiety',
        $model->after_post_frequency_after_meal_satiety = isset($payload['after_post_frequency_after_meal_satiety']) && !empty($payload['after_post_frequency_after_meal_satiety']) ? $payload['after_post_frequency_after_meal_satiety'] : '';
        //  治疗后-频率-早饱
        // 'after_post_frequency_premature_satiety',
        $model->after_post_frequency_premature_satiety = isset($payload['after_post_frequency_premature_satiety']) && !empty($payload['after_post_frequency_premature_satiety']) ? $payload['after_post_frequency_premature_satiety'] : '';
        // 治疗后-频率-上腹烧灼
        // 'after_post_frequency_burn_upper_abdomen',
        $model->after_post_frequency_burn_upper_abdomen = isset($payload['after_post_frequency_burn_upper_abdomen']) && !empty($payload['after_post_frequency_burn_upper_abdomen']) ? $payload['after_post_frequency_burn_upper_abdomen'] : '';

        // 治疗后-频率-总分
        // 'after_post_frequency_amount ',
        $model->after_post_frequency_amount  = isset($payload['after_post_frequency_amount ']) && !empty($payload['after_post_frequency_amount ']) ? $payload['after_post_frequency_amount '] : '';

        // 治疗后-其他-泛酸
        // 'after_other_acid_regurgitation',
        $model->after_other_acid_regurgitation = isset($payload['after_other_acid_regurgitation']) && !empty($payload['after_other_acid_regurgitation']) ? $payload['after_other_acid_regurgitation'] : '';
        //  治疗后-其他-烧心
        // 'after_other_heartburn',
        $model->after_other_heartburn = isset($payload['after_other_heartburn']) && !empty($payload['after_other_heartburn']) ? $payload['after_other_heartburn'] : '';
        //  治疗后-其他-大便
        // 'after_other_shit',
        $model->after_other_shit = isset($payload['after_other_shit']) && !empty($payload['after_other_shit']) ? $payload['after_other_shit'] : '';
        // 治疗后-其他-疲乏
        // 'after_other_fatigued',
        $model->after_other_fatigued = isset($payload['after_other_fatigued']) && !empty($payload['after_other_fatigued']) ? $payload['after_other_fatigued'] : '';
        //  治疗后-其他-睡眠差
        // 'after_other_poor_sleep',
        $model->after_other_poor_sleep = isset($payload['after_other_poor_sleep']) && !empty($payload['after_other_poor_sleep']) ? $payload['after_other_poor_sleep'] : '';
        //  治疗后-其他-烦躁易怒
        // 'after_other_irritability',
        $model->after_other_irritability = isset($payload['after_other_irritability']) && !empty($payload['after_other_irritability']) ? $payload['after_other_irritability'] : '';
        //  治疗后-其他-焦虑
        // 'after_other_anxiety',
        $model->after_other_anxiety = isset($payload['after_other_anxiety']) && !empty($payload['after_other_anxiety']) ? $payload['after_other_anxiety'] : '';
        //  治疗后-其他-抑郁
        // 'after_other_depressed',
        $model->after_other_depressed = isset($payload['after_other_depressed']) && !empty($payload['after_other_depressed']) ? $payload['after_other_depressed'] : '';

        // 是否产生不良反应
        $model->adversereaction = isset($payload['adversereaction']) && !empty($payload['adversereaction']) ? $payload['adversereaction'] : '';
        // 反应表现复选id
        $model->adversereaction_group = isset($payload['adversereaction_group']) && !empty($payload['adversereaction_group']) ? $payload['adversereaction_group'] : '';
        // 反应表现其他输入
        $model->adversereaction_group_input = isset($payload['adversereaction_group_input']) && !empty($payload['adversereaction_group_input']) ? $payload['adversereaction_group_input'] : '';
        // 日期
        $model->adversereaction_date = isset($payload['adversereaction_date']) && !empty($payload['adversereaction_date']) ? $payload['adversereaction_date'] : '';
        // 是否用药后立即发生
        $model->adversereaction_immediately = isset($payload['adversereaction_immediately']) && !empty($payload['adversereaction_immediately']) ? $payload['adversereaction_immediately'] : '';
        // 用药几小时
        $model->adversereaction_time_input = isset($payload['adversereaction_time_input']) && !empty($payload['adversereaction_time_input']) ? $payload['adversereaction_time_input'] : '';
        // 不良反应的严重程度单选id
        $model->adversereaction_degree = isset($payload['adversereaction_degree']) && !empty($payload['adversereaction_degree']) ? $payload['adversereaction_degree'] : '';
        // 药物相关
        $model->adversereaction_related = isset($payload['adversereaction_related']) && !empty($payload['adversereaction_related']) ? $payload['adversereaction_related'] : '';

        $model->attachments = isset($payload['attachments']) && !empty($payload['attachments']) ? $payload['attachments'] : '';

        $model->status = 0;
        return $model->save();
    }
}
